package com.hjxr.sysadmin.zsj.controller;

import java.util.List;

import com.hjxr.sysadmin.uitl.poi.ExcelUtil;
import com.hjxr.sysadmin.web.controller.BaseController;
import com.hjxr.sysadmin.web.page.TableDataInfo;
import com.hjxr.sysadmin.zsj.domain.ZIndustry;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hjxr.framework.aspectj.lang.annotation.Log;
import com.hjxr.framework.aspectj.lang.enums.BusinessType;
import com.hjxr.sysadmin.zsj.domain.Building;
import com.hjxr.sysadmin.zsj.service.IBuildingService;
import com.hjxr.framework.web.domain.AjaxResult;

/**
 * 楼宇信息Controller
 *
 * @author xk
 * @date 2021-03-23
 */
@Api("楼宇信息")
@RestController
@RequestMapping("/zsj/building")
public class BuildingController extends BaseController
{
    @Autowired
    private IBuildingService buildingService;

    /**
     * 查询楼宇信息列表
     */
    @ApiOperation("查询楼宇信息列表")
    @GetMapping("/list")
    public TableDataInfo list(Building building)
    {
        startPage();
        List<Building> list = buildingService.selectBuildingList(building);
        return getDataTable(list);
    }

    /**
     * 导出楼宇信息列表
     */
    @ApiOperation("导出楼宇信息列表")
    @Log(title = "楼宇信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Building building)
    {
        List<Building> list = buildingService.selectBuildingList(building);
        ExcelUtil<Building> util = new ExcelUtil<Building>(Building.class);
        return util.exportExcel(list, "building");
    }

    /**
     * 获取楼宇信息详细信息
     */
    @ApiOperation("获取楼宇信息详细信息")
    @GetMapping(value = "/{buildingId}")
    public AjaxResult getInfo(@PathVariable("buildingId") Long buildingId)
    {
        return AjaxResult.success(buildingService.selectBuildingById(buildingId));
    }

    /**
     * 新增楼宇信息
     */
    @ApiOperation("新增楼宇信息")
    @Log(title = "楼宇信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Building building)
    {
        return toAjax(buildingService.insertBuilding(building));
    }

    /**
     * 修改楼宇信息
     */
    @ApiOperation("修改楼宇信息")
    @Log(title = "楼宇信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Building building)
    {
        return toAjax(buildingService.updateBuilding(building));
    }

    /**
     * 删除楼宇信息
     */
    @ApiOperation("删除楼宇信息")
    @Log(title = "楼宇信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{buildingIds}")
    public AjaxResult remove(@PathVariable Long[] buildingIds)
    {
        return toAjax(buildingService.deleteBuildingByIds(buildingIds));
    }

    /**
     * 获取楼宇主导产业信息详
     */
    @ApiOperation("获取楼宇主导产业信息详")
    @GetMapping(value = "/industry/{buildingId}")
    public AjaxResult selectIndustryById(@PathVariable("buildingId") Long buildingId)
    {
        return AjaxResult.success(buildingService.selectIndustryById(buildingId));
    }
    /**
     * 新增楼宇主导产业信息
     */
    @ApiOperation("新增楼宇主导产业信息")
    @Log(title = "新增楼宇主导产业信息", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/addindustry")
    public AjaxResult insertIndustry(@RequestBody ZIndustry zIndustry)
    {
        return toAjax(buildingService.insertIndustry(zIndustry));
    }

    /**
     * 修改楼宇主导产业信息
     */
    @ApiOperation("修改楼宇主导产业信息")
    @Log(title = "修改楼宇主导产业信息", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/editindustry")
    public AjaxResult updateIndustry(@RequestBody ZIndustry zIndustry)
    {
        return toAjax(buildingService.updateIndustry(zIndustry));
    }
}
